using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace marbletrack
{
    class CameraDisc
    {
        static public bool DiscAlive;
        protected static Texture2D Disc = Game1.contentloader.Load<Texture2D>("Textures//Button Texture//CameraWheel");
        protected const int FRAMETIMERACTIVATE = 1;
        protected Vector2 nextMousePostion = new Vector2();
        protected int prevScrollValue = 0;

        public CameraDisc()
        {

        }

        public void Update()
        {
            int mouseScrollVal = Mouse.GetState().ScrollWheelValue;
            prevScrollValue = mouseScrollVal - prevScrollValue;

            if (prevScrollValue > 0 && Game1.camposModifier>1000)//near zoom distance
            {
                Game1.camposModifier -= 1000;//amount modified each update wheel is scrolled
            }
            else if (prevScrollValue < 0 && Game1.camposModifier<10000)//far zoom distance
            {
                Game1.camposModifier += 1000;
            }
            prevScrollValue = mouseScrollVal;

            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                DiscAlive = true;
                nextMousePostion.X = Mouse.GetState().X;
                nextMousePostion.Y = Mouse.GetState().Y;

                Game1.camangle.Y += 10*(nextMousePostion.X -(Game1.Graphics.GraphicsDevice.Viewport.Width/2))/Game1.Graphics.GraphicsDevice.Viewport.Width;//rotation round y axis
                Game1.camangle.X -= 10*(nextMousePostion.Y - (Game1.Graphics.GraphicsDevice.Viewport.Height/2))/Game1.Graphics.GraphicsDevice.Viewport.Height;//rotation round x axis
            }
            else
            {
                DiscAlive = false;
            }
        }

        public void Draw()
        {
            if (DiscAlive)
            {
                const int SIZE = 125;
                Viewport viewport = Game1.Graphics.GraphicsDevice.Viewport;
                SpriteBatch spriteBatch = Game1.SpriteBatch;
                spriteBatch.Begin();
                spriteBatch.Draw(Disc, new Microsoft.Xna.Framework.Rectangle(viewport.Width / 2 - SIZE / 2, viewport.Height / 2 - SIZE / 2, SIZE, SIZE), Color.White);
                spriteBatch.End();
            }
        }
    }
}
